from datetime import datetime
import pandas as pd
from pathlib import Path
import plotly
import plotly.express as px
import numpy as np
from statsmodels.tsa.api import VAR
import urllib.request
plotly.offline.init_notebook_mode()
NOW = datetime.now()
TODAY = NOW.date()
print('Aktualisiert:', NOW)
Aktualisiert: 2021-04-09 14:11:11.299022
STATE_NAMES = ['Burgenland', 'Kärnten', 'Niederösterreich',
'Oberösterreich', 'Salzburg', 'Steiermark',
'Tirol', 'Vorarlberg', 'Wien']
# TODO: Genauer recherchieren!
EVENTS = {'1. Lockdown': (np.datetime64('2020-03-20'), np.datetime64('2020-04-14'),
'red', 'inside top left'),
'1. Maskenpflicht': (np.datetime64('2020-03-30'), np.datetime64('2020-06-15'),
'yellow', 'inside bottom left'),
'2. Maskenpflicht': (np.datetime64('2020-07-24'), np.datetime64(TODAY),
'yellow', 'inside bottom left'),
'1. Soft Lockdown': (np.datetime64('2020-11-03'), np.datetime64('2020-11-17'),
'orange', 'inside top left'),
'2. Lockdown': (np.datetime64('2020-11-17'), np.datetime64('2020-12-06'),
'red', 'inside top left'),
'2. Soft Lockdown': (np.datetime64('2020-12-06'), np.datetime64('2020-12-27'),
'orange', 'inside top left'),
'Weihnachten 2020': (np.datetime64('2020-12-24'), np.datetime64('2020-12-27'),
'blue', 'inside top left'),
'3. Lockdown': (np.datetime64('2020-12-27'), np.datetime64(TODAY),
'red', 'inside top left')}
def load_data(URL, date_columns):
data_file = Path(URL).name
try:
# Only download the data if we don't have it, to avoid
# excessive server access during local development
with open(data_file):
print("Using local", data_file)
except FileNotFoundError:
print("Downloading", URL)
urllib.request.urlretrieve(URL, data_file)
return pd.read_csv(data_file, sep=';', parse_dates=date_columns, infer_datetime_format=True, dayfirst=True)
raw_data = load_data("https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv", [0])
additional_data = load_data("https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv", [0, 2])
Downloading https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv Downloading https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv
cases = raw_data.query("Bundesland == 'Österreich'")
cases.insert(0, 'AnzahlFaelle_avg7', cases.AnzahlFaelle7Tage / 7)
time = cases.Time
tests = additional_data.query("Bundesland == 'Alle'")
tests.insert(2, 'TagesTests', np.concatenate([[np.nan], np.diff(tests.TestGesamt)]))
tests.insert(3, 'TagesTests_avg7', np.concatenate([[np.nan] * 7, (tests.TestGesamt.values[7:] - tests.TestGesamt.values[:-7])/7]))
tests.insert(0, 'Time', tests.MeldeDatum)
fig = px.line(cases, x='Time', y=["AnzahlFaelle", "AnzahlFaelle_avg7"], log_y=True, title="Fallzahlen")
fig.add_scatter(x=tests.Time, y=tests.TagesTests, name='Tests')
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
all_data = tests.merge(cases, on='Time', how='outer')
all_data.insert(1, 'PosRate', all_data.AnzahlFaelle / all_data.TagesTests)
all_data.insert(1, 'PosRate_avg7', all_data.AnzahlFaelle_avg7 / all_data.TagesTests_avg7)
fig = px.line(all_data, x='Time', y=['PosRate', 'PosRate_avg7'], log_y=False, title="Anteil Positiver Tests")
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
states = []
rates = []
for state_name, state_data in raw_data.groupby('Bundesland'):
x = np.log2(state_data.AnzahlFaelle7Tage)
rate = 2**np.array(np.diff(x))
rates.append(rate)
states.append(state_name)
growth = pd.DataFrame({n: r for n, r in zip(states, rates)})
fig = px.line(growth, x=time[1:], y=STATE_NAMES, title='Wachstumsrate')
fig.update_layout(yaxis=dict(range=[0.25, 4]))
fig.show()
/usr/share/miniconda/lib/python3.8/site-packages/pandas/core/series.py:726: RuntimeWarning: divide by zero encountered in log2 /usr/share/miniconda/lib/python3.8/site-packages/numpy/lib/function_base.py:1280: RuntimeWarning: invalid value encountered in subtract
model = VAR(growth[150:][STATE_NAMES])
res = model.fit(1)
res.summary()
Summary of Regression Results
==================================
Model: VAR
Method: OLS
Date: Fri, 09, Apr, 2021
Time: 14:11:15
--------------------------------------------------------------------
No. of Equations: 9.00000 BIC: -47.4510
Nobs: 256.000 HQIC: -48.1961
Log likelihood: 3054.03 FPE: 7.09822e-22
AIC: -48.6974 Det(Omega_mle): 5.02776e-22
--------------------------------------------------------------------
Results for equation Burgenland
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.442701 0.125669 3.523 0.000
L1.Burgenland 0.069572 0.062134 1.120 0.263
L1.Kärnten -0.220007 0.053935 -4.079 0.000
L1.Niederösterreich 0.061426 0.136761 0.449 0.653
L1.Oberösterreich 0.222771 0.127550 1.747 0.081
L1.Salzburg 0.270016 0.070056 3.854 0.000
L1.Steiermark 0.145501 0.089886 1.619 0.106
L1.Tirol 0.117208 0.061385 1.909 0.056
L1.Vorarlberg -0.034440 0.056720 -0.607 0.544
L1.Wien -0.062434 0.116170 -0.537 0.591
======================================================================================
Results for equation Kärnten
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.490029 0.148808 3.293 0.001
L1.Burgenland -0.002458 0.073574 -0.033 0.973
L1.Kärnten 0.331838 0.063866 5.196 0.000
L1.Niederösterreich 0.079812 0.161941 0.493 0.622
L1.Oberösterreich -0.061832 0.151035 -0.409 0.682
L1.Salzburg 0.218113 0.082955 2.629 0.009
L1.Steiermark 0.115238 0.106436 1.083 0.279
L1.Tirol 0.140909 0.072687 1.939 0.053
L1.Vorarlberg 0.153722 0.067163 2.289 0.022
L1.Wien -0.452406 0.137559 -3.289 0.001
======================================================================================
Results for equation Niederösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.290571 0.062240 4.669 0.000
L1.Burgenland 0.090771 0.030773 2.950 0.003
L1.Kärnten -0.015259 0.026712 -0.571 0.568
L1.Niederösterreich 0.051617 0.067733 0.762 0.446
L1.Oberösterreich 0.282567 0.063172 4.473 0.000
L1.Salzburg 0.020887 0.034696 0.602 0.547
L1.Steiermark 0.023770 0.044518 0.534 0.593
L1.Tirol 0.068845 0.030402 2.264 0.024
L1.Vorarlberg 0.079871 0.028092 2.843 0.004
L1.Wien 0.111283 0.057535 1.934 0.053
======================================================================================
Results for equation Oberösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.214226 0.062121 3.449 0.001
L1.Burgenland 0.021095 0.030714 0.687 0.492
L1.Kärnten 0.007801 0.026661 0.293 0.770
L1.Niederösterreich 0.048049 0.067604 0.711 0.477
L1.Oberösterreich 0.401039 0.063051 6.361 0.000
L1.Salzburg 0.083766 0.034630 2.419 0.016
L1.Steiermark 0.136297 0.044433 3.067 0.002
L1.Tirol 0.048940 0.030344 1.613 0.107
L1.Vorarlberg 0.082477 0.028038 2.942 0.003
L1.Wien -0.043694 0.057425 -0.761 0.447
======================================================================================
Results for equation Salzburg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.508445 0.121730 4.177 0.000
L1.Burgenland 0.086604 0.060186 1.439 0.150
L1.Kärnten 0.010506 0.052244 0.201 0.841
L1.Niederösterreich -0.013819 0.132474 -0.104 0.917
L1.Oberösterreich 0.138142 0.123552 1.118 0.264
L1.Salzburg 0.057951 0.067860 0.854 0.393
L1.Steiermark 0.071860 0.087068 0.825 0.409
L1.Tirol 0.212981 0.059461 3.582 0.000
L1.Vorarlberg 0.031839 0.054942 0.580 0.562
L1.Wien -0.096202 0.112528 -0.855 0.393
======================================================================================
Results for equation Steiermark
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.179638 0.095389 1.883 0.060
L1.Burgenland -0.015283 0.047163 -0.324 0.746
L1.Kärnten -0.010557 0.040939 -0.258 0.797
L1.Niederösterreich -0.019559 0.103808 -0.188 0.851
L1.Oberösterreich 0.402941 0.096817 4.162 0.000
L1.Salzburg 0.018479 0.053176 0.348 0.728
L1.Steiermark -0.001535 0.068228 -0.022 0.982
L1.Tirol 0.155780 0.046594 3.343 0.001
L1.Vorarlberg 0.048910 0.043053 1.136 0.256
L1.Wien 0.246069 0.088178 2.791 0.005
======================================================================================
Results for equation Tirol
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.243330 0.117196 2.076 0.038
L1.Burgenland 0.019032 0.057945 0.328 0.743
L1.Kärnten -0.066510 0.050299 -1.322 0.186
L1.Niederösterreich -0.067481 0.127540 -0.529 0.597
L1.Oberösterreich 0.021789 0.118950 0.183 0.855
L1.Salzburg 0.080482 0.065332 1.232 0.218
L1.Steiermark 0.336948 0.083825 4.020 0.000
L1.Tirol 0.461014 0.057246 8.053 0.000
L1.Vorarlberg 0.147177 0.052896 2.782 0.005
L1.Wien -0.171216 0.108337 -1.580 0.114
======================================================================================
Results for equation Vorarlberg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.158064 0.139102 1.136 0.256
L1.Burgenland 0.043706 0.068776 0.635 0.525
L1.Kärnten -0.074258 0.059700 -1.244 0.214
L1.Niederösterreich 0.152042 0.151379 1.004 0.315
L1.Oberösterreich 0.003386 0.141184 0.024 0.981
L1.Salzburg 0.205960 0.077544 2.656 0.008
L1.Steiermark 0.122189 0.099494 1.228 0.219
L1.Tirol 0.055522 0.067946 0.817 0.414
L1.Vorarlberg 0.099842 0.062783 1.590 0.112
L1.Wien 0.238604 0.128587 1.856 0.064
======================================================================================
Results for equation Wien
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.582964 0.075241 7.748 0.000
L1.Burgenland -0.038433 0.037201 -1.033 0.302
L1.Kärnten -0.024303 0.032292 -0.753 0.452
L1.Niederösterreich 0.026823 0.081882 0.328 0.743
L1.Oberösterreich 0.326444 0.076367 4.275 0.000
L1.Salzburg 0.019598 0.041944 0.467 0.640
L1.Steiermark -0.037305 0.053817 -0.693 0.488
L1.Tirol 0.088287 0.036753 2.402 0.016
L1.Vorarlberg 0.110172 0.033960 3.244 0.001
L1.Wien -0.046571 0.069554 -0.670 0.503
======================================================================================
Correlation matrix of residuals
Burgenland Kärnten Niederösterreich Oberösterreich Salzburg Steiermark Tirol Vorarlberg Wien
Burgenland 1.000000 0.141076 0.055229 0.162003 0.220305 0.071812 0.081705 0.007268 0.156051
Kärnten 0.141076 1.000000 0.026160 0.203248 0.177950 -0.064743 0.161409 0.027215 0.305309
Niederösterreich 0.055229 0.026160 1.000000 0.238676 0.070857 0.317130 0.138787 0.031244 0.301661
Oberösterreich 0.162003 0.203248 0.238676 1.000000 0.300883 0.260606 0.090284 0.060208 0.136890
Salzburg 0.220305 0.177950 0.070857 0.300883 1.000000 0.152972 0.052147 0.090406 0.002665
Steiermark 0.071812 -0.064743 0.317130 0.260606 0.152972 1.000000 0.105318 0.097008 -0.107267
Tirol 0.081705 0.161409 0.138787 0.090284 0.052147 0.105318 1.000000 0.163404 0.146763
Vorarlberg 0.007268 0.027215 0.031244 0.060208 0.090406 0.097008 0.163404 1.000000 0.000284
Wien 0.156051 0.305309 0.301661 0.136890 0.002665 -0.107267 0.146763 0.000284 1.000000